﻿' ****************************************************************************
' Copyright (C) 2009 Tony George
' 
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 2 of the License, or
' (at your option) any later version.
' 
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
' 
' You should have received a copy of the GNU General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
'
' ****************************************************************************

Public Class frmVariables
    Private Sub frmVariables_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If SelectedTask Is Nothing Then
            Me.txtVarName.Text = ""
            Me.txtVarValue.Text = ""
        Else
            Dim s As String = SelectedTask.Text
            s = s.Replace("SetEnvironment=" & """", "")
            s = s.Remove(s.Length - 1, 1)
            Dim arr() As String = Split(s, "=")

            Me.txtVarName.Text = arr(0)
            Me.txtVarValue.Text = arr(1).Replace("\\", "\").Replace("\""", """")
        End If
    End Sub

    Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
        Me.Close()
    End Sub

    Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
        If Me.txtVarName.Text.Trim = "" Then
            MsgBox(GetLangString("2117"))
            Exit Sub
        End If

        Dim s As String = ""
        s += "SetEnvironment="
        s += """"
        s += Me.txtVarName.Text
        s += "=" & Me.txtVarValue.Text.Replace("\", "\\").Replace("""", "\""")
        s += """"

        If SelectedTask Is Nothing Then
            frmMain.lvTasks.Items.Add(s).Checked = True
        Else
            SelectedTask.Text = s
        End If

        Me.Close()
    End Sub
End Class